#!/usr/bin/env python

import sys
from ejercicio1 import *
from time import localtime, strftime

FIBRA = 2 * 10.0**2		# velocidad de fibra optica en ms

if __name__ == "__main__":
	if len(sys.argv) < 4:
		print "experimentos1.py [reps] [file entrada] [file salida]"
		exit()
	
	reps = int(sys.argv[1])
	inifile = open(sys.argv[2])
	outfile = open(sys.argv[3], "w")
	
	print "#Formato salida: [host] [tiempo_ping ms] [hr envio] [vel fibra ms] [ping linux ms]"
	outfile.write("host ping hr fibra lping\n")
	for univ in inifile:
		if univ[0] == "#":
			continue
			
		host = univ.split("\t")[0]
		name = univ.split("\t")[1]
		dist = int(univ.split("\t")[2])
		
		res = ej1(host, reps)
		hora = strftime("%H", localtime())
		fibra = str(2*dist/FIBRA)
		
		lping = linux_ping(host, reps)
		
		string = (host + " " + str(res) + " " + hora + " " + fibra + " " + lping).strip()
		print string
		outfile.write(string+"\n")

